package com.febers.ihealth.fragment

import android.view.View
import com.febers.ihealth.R
import com.febers.ihealth.base.BaseFragment
import com.febers.ihealth.entity.ReleaseNextSurveyEvent
import com.febers.ihealth.utils.Event
import com.febers.ihealth.utils.log
import com.febers.ihealth.utils.user
import kotlinx.android.synthetic.main.survey_hanfeng_fare.*

class SurveyHanfengFare: BaseFragment() {

    private var chooseEfengEhan = false
    private var chooseFareQingkuang = false

    override fun setView(): Int = R.layout.survey_hanfeng_fare

    override fun initView() {
        if (user.ehanEfeng) {
            tv_title_ehan_efeng.visibility = View.VISIBLE
            radio_group_ehan_efeng.visibility = View.VISIBLE
            radio_group_ehan_efeng.setOnCheckedChangeListener { radioGroup, id ->
                log {
                    "恶风恶寒被点击 $chooseFareQingkuang"
                }
                user.clearEfengEhan()
                when(id) {
                    R.id.radio_button_yanzhong_ehan -> user.yanzhongEhan = true
                    R.id.radio_button_weie_fenghan -> user.weieFenghan = true
                    R.id.radio_button_e_fenghan -> user.eFenghan = true
                    R.id.radio_button_e_feng -> user.eFeng
                }
                chooseEfengEhan = true
                if (chooseFareQingkuang) {
                    Event.post(ReleaseNextSurveyEvent(true))
                }
            }
        } else {
            tv_title_ehan_efeng.visibility = View.GONE
            radio_group_ehan_efeng.visibility = View.GONE
            chooseEfengEhan = true
        }

        if(user.fare) {
            radio_group_fare_detail.setOnCheckedChangeListener { radioGroup, id ->
                log {
                    "发热情况被点击 $chooseEfengEhan"
                }
                user.clearFare()
                when(id) {
                    R.id.radio_btn_chixu_gaore -> user.chixuGaore = true
                    R.id.radio_btn_chixu_zhongre -> user.chixuZhongre = true
                    R.id.radio_btn_chixu_dire -> user.chixuDire = true
                    R.id.radio_btn_wuhou_chaore -> user.wuhouChaore = true
                    R.id.radio_btn_zaochen_fare -> user.zaochenFare = true
                    R.id.radio_btn_yejian_fare -> user.yejianFare = true
                    R.id.radio_btn_buguilv -> user.fareBuguilv = true
                    R.id.radio_btn_shenre_zhihan -> user.shenreZhihan = true
                }
                radio_btn_wanglaihanre.clearCheck()
                chooseFareQingkuang = true
                if (chooseEfengEhan) {
                    Event.post(ReleaseNextSurveyEvent(true))
                }
            }
            radio_btn_shenre_zhihan.setOnCheckedChangeListener { compoundButton, checked ->
                user.shenreZhihan = checked
            }
            radio_btn_wanglaihanre.setOnCheckedChangeListener { buttonView, isChecked ->
                user.wanglaihanre = isChecked
                if (isChecked) {
                    radio_group_fare_detail.clearCheck()
                }
            }
        } else {
            tv_title_fare.visibility = View.GONE
            radio_group_fare_detail.visibility = View.GONE
            radio_btn_shenre_zhihan.visibility = View.GONE
            radio_btn_wanglaihanre.visibility = View.GONE
            chooseFareQingkuang = true
        }
    }

    override fun lazyInit() {
    }

    override fun onVisible() {
        Event.post(ReleaseNextSurveyEvent(false))
        if (chooseEfengEhan && chooseFareQingkuang) {
            Event.post(ReleaseNextSurveyEvent(true))
        }
    }
}